package NewTmas;

import taskmaster.job.Task;
import taskmaster.job.TaskCollection;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: abhatnag
 * Date: 8/16/11
 * Time: 8:53 AM
 * To change this template use File | Settings | File Templates.
 */
public class TableRowColorRenderer extends DefaultTableCellRenderer {

    TaskCollection tc;

    public TableRowColorRenderer(TaskCollection tc) {
        this.tc=tc;

        setOpaque(true);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        String jobname= table.getValueAt(row,table.convertColumnIndexToModel(0)).toString();
        String task=table.getValueAt(row,table.convertColumnIndexToModel(1)).toString();


        Task t= tc.getTask(jobname,task);


        if(t.getStatusId()==-6 || t.getStatusId()==-4 || t.getStatusId()==-3 || t.getStatusId()==-2) {
               setBackground(Color.decode("#F08080"));
        }
        else{
            setBackground(Color.WHITE);
        }


        setText(value !=null ? value.toString() : "");

       return this;

    }
}
